package com.itheima;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
        test2();
    }

    public static void test2() {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        });
        treeMap.put(new Student("小杨",21),"深圳");
        treeMap.put(new Student("小张",14),"上海");
        treeMap.put(new Student("小帅",20),"成都");
        treeMap.put(new Student("小杨",41),"厦门");
        treeMap.put(new Student("小章",54),"西安");
        treeMap.put(new Student("小和",52),"广州");

        treeMap.forEach((k,v)-> System.out.println(k +":"+v));

    }



    public static void test1() {
        TreeMap<Student,String>treeMap = new TreeMap<>();

        treeMap.put(new Student("小杨",21),"深圳");
        treeMap.put(new Student("小张",14),"深圳");
        treeMap.put(new Student("小帅",20),"深圳");
        treeMap.put(new Student("小杨",41),"深圳");
        treeMap.put(new Student("小章",54),"深圳");
        treeMap.put(new Student("小和",2),"深圳");

        treeMap.forEach((k,v)-> System.out.println(k +":"+v));

    }
}

